﻿using Model;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using Utility;

namespace ConsoleApp1
{
    class Program
    {
        static NLog.Logger _logger = NLog.LogManager.GetCurrentClassLogger();

        static void Main(string[] args)
        {
            //var arr = args[0].Split(new string[] { "@@" }, StringSplitOptions.RemoveEmptyEntries);
            //int city = Convert.ToInt32(args[0]);

            //single_cell_simulate(571, 30.311251, 120.209501, 30, 15, 38400, 120, 10, "sssssss");

            winprop.wrapper wrapper = new winprop.wrapper();
            wrapper.init("UTM", 50000, 0, 117, 0);
            wrapper.BiuldODAFile(@"D:\winprop\map\杭州市", @"D:\winprop\output1\");

        }


        
        public static void single_cell_simulate(int cityCode, double cell_latitude, double cell_longitude, double ant_height, double power, double frequency, int azimuth, double downtilt, string id)
        {
            winprop.wrapper wrapper = new winprop.wrapper();

            string odaFilePath = getODAByCity(cityCode);
            _logger.Debug(odaFilePath);
            wrapper.load_building(odaFilePath);

            string outputFolder = System.IO.Path.Combine(System.Configuration.ConfigurationManager.AppSettings["outputfolder"], id);
            double mx = 0, my = 0;
            MecatorUtil.loc_to_mercator(cell_longitude, cell_latitude, ref mx, ref my);
            if (downtilt > 0)
            {
                downtilt = downtilt - 6;
            }
            winprop.Freq freq = new winprop.Freq();
            _logger.Debug("start");
            int error = wrapper.single_cell_winprop(outputFolder, cityCode, 5, 500, 20, new Res_Cell()
            {
                AntHeight = ant_height,
                CellLatitude = my,
                CellLongitude = mx,
                CellName = id,
                Frequency = freq.GetFreqByCenterChannelNumber(frequency.ToString()),
                HorizonAngleToEast = azimuth,
                VerticalAngleToHorizontal = downtilt,
                RSTxPower = power
            });
            _logger.Debug("end");
            wrapper.release_building();
        }
        private static string getODAByCity(int cityCode)
        {
            return System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "oda", cityCode.ToString() + ".oda");
        }
    }
}
